package cn.xshi.oauth.service.impl;
import java.util.List;
import java.util.Map;

import cn.xshi.oauth.param.OauthRoleParam;
import cn.xshi.oauth.service.OauthRoleService;
import cn.xshi.common.base.BaseService;
import cn.xshi.common.util.ExceptionUtil;
import org.springframework.stereotype.Service;
import cn.xshi.oauth.dao.OauthRoleDao;
import cn.xshi.oauth.model.OauthRole;
import javax.annotation.Resource;
/**
 * @Desc 角色模块
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Service
public class OauthRoleServiceImpl extends BaseService implements OauthRoleService {

	@Resource
	private OauthRoleDao oauthRoleDao;

	/**
	 * 分页
	 * @param condition
	 * @return
	 */
	public List<OauthRole> getOauthRoleListByCondition(Map<String,Object> condition){
		try{
			return oauthRoleDao.getOauthRoleListByCondition(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	 * 查询对象
	 * @param id
	 * @return
	 */
	public OauthRole getOauthRoleById(String id){
		try{
			OauthRole oauthRole = oauthRoleDao.getOauthRoleById(id);
			return oauthRole;
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	 * 添加
	 * @param oauthRole
	 * @return
	 */
	public int addOauthRole(OauthRole oauthRole){
		int i = 0;
		try {
			oauthRole.setId(toUUID());
			oauthRole.setCreateId(getCurrentAccountId());
			oauthRole.setCreateTime(getDate());
			i = oauthRoleDao.addOauthRole(oauthRole);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 修改
	 * @param oauthRole
	 * @return
	 */
	public int updateOauthRole(OauthRole oauthRole){
		int i = 0;
		try {
			oauthRole.setUpdateId(getCurrentAccountId());
			oauthRole.setUpdateTime(getDate());
			i = oauthRoleDao.updateOauthRole(oauthRole);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 修改（根据动态条件）
	 * @param oauthRole
	 * @return
	 */
	public int updateOauthRoleBySelective(OauthRole oauthRole){
		int i = 0;
		try {
			oauthRole.setUpdateId(getCurrentAccountId());
			oauthRole.setUpdateTime(getDate());
			i = oauthRoleDao.updateOauthRoleBySelective(oauthRole);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 删除
	 * @param condition
	 * @return
	 */
	public int delOauthRole(Map<String,Object> condition){
		int i = 0;
		try {
			i = oauthRoleDao.delOauthRole(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 批量修改
	 * @param oauthRoleList
	 * @return
	 */
	public int updateBatchOauthRole(List<OauthRole> oauthRoleList){
		int i = 0;
		try {
			i = oauthRoleDao.updateBatchOauthRole(oauthRoleList);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 批量修改（根据动态条件）
	 * @param oauthRoleList
	 * @return
	 */
	public int updateBatchOauthRoleBySelective(List<OauthRole> oauthRoleList){
		int i = 0;
		try {
			i = oauthRoleDao.updateBatchOauthRoleBySelective(oauthRoleList);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 恢复
	 * @param condition
	 * @return
	 */
	public int recoverOauthRole(Map<String, Object> condition){
		int i = 0;
		try {
			i = oauthRoleDao.recoverOauthRole(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 查询角色列表
	 * @param oauthRoleParam
	 * @return
	 */
	public List<OauthRole> getOauthRoleList(OauthRoleParam oauthRoleParam){
		return  oauthRoleDao.getOauthRoleList(oauthRoleParam);
	}
}